package com.example.administrator.myapplication.Model;

import android.content.Context;

import com.example.administrator.myapplication.Bean.AjaxResult;
import com.example.administrator.myapplication.Bean.DuanziBean;
import com.example.administrator.myapplication.Http.Api;
import com.example.administrator.myapplication.Http.RetrofitHelper;
import com.example.administrator.myapplication.Presenter.ILoginListener;
import com.example.administrator.myapplication.Presenter.IOnLoadListener;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2019/6/14 0014.
 */

public class LoginModel implements ILoginModel {
    @Override
    public void login(String username,String password,boolean rememberMe,String validateCode,final ILoginListener iLoginListener) {
        RetrofitHelper retrofitHelper = new RetrofitHelper(Api.Server_Host);
        retrofitHelper.login(username,password,validateCode,rememberMe).enqueue(new Callback<AjaxResult>() {
            @Override
            public void onResponse(Call<AjaxResult> call, Response<AjaxResult> response) {
                iLoginListener.success(response.body());
            }

            @Override
            public void onFailure(Call<AjaxResult> call, Throwable t) {
                iLoginListener.fail(t.toString());
            }
        });
    }
}
